;;; -*- mode: lisp -*-

;; CL-EN
;;  Copyright 2008 Ben Hyde <bhyde@pobox.com>

(in-package "ECHONEST")


;;;; Classes for the API responses.

(defclass thing ()
  ((parent :initform nil :initarg :parent)))

(defclass response (thing)
  ((id :initform nil) 
   (input :initform nil)
   status))
 
(defclass decoder (thing)
  (version
   name))

(defclass analysis (thing)
  (decoder
   track))

(defclass track (thing)
  (version
   usable-duration
   duration
   (tags :initform nil)
   tatums
   (sections :initform nil)
   (segments :initform nil)))

(defclass section (thing)
  (start
   duration))

(defclass segment (thing)
  (start
   duration
   (tags :initform nil)))


(define-tag number-of-tatums-per-beat "numTatumsPerBeat" integer)
(define-tag number-of-Segments "numSegments" integer)
(define-tag pitch-variance "pitchVariance" floats)
(define-tag size-pitches "sizePitches" integer)
(define-tag number-of-beats "numBeats" integer)
(define-tag time-signature "timeSignature" integer)
(define-tag tatum-confidence "tatumConfidence" float)
(define-tag number-of-sections "numSections" integer)
(define-tag segment-duration-mean "segmentDurationMean" float)
(define-tag tempo "tempo" float)
(define-tag loudness "loudness" float)
(define-tag tempo-confidence "tempoConfidence" float)
(define-tag number-of-tatums "numTatums" integer)
(define-tag time-Loudness-Max-Mean "timeLoudnessMaxMean" float)
(define-tag tatum "tatum" float)
(define-tag start-Of-Fade-Out "startOfFadeOut" float)
(define-tag pitch-Mean "pitchMean" floats)
(define-tag size-Timbre "sizeTimbre" integer)
(define-tag segment-Duration-Variance "segmentDurationVariance" float)
(define-tag loudness-Max-Mean "loudnessMaxMean" float)
(define-tag loudness-Max-Variance "loudnessMaxVariance" float)
(define-tag timbre-Variance "timbreVariance" floats)
(define-tag loudness-Dynamics-Mean "loudnessDynamicsMean" float)
(define-tag time-Signature-Stability "timeSignatureStability" float)
(define-tag beat-Variance "beatVariance" float)
(define-tag loudness-Begin-Mean "loudnessBeginMean" float)
(define-tag loudness-Begin-Variance "loudnessBeginVariance" float)
(define-tag end-Of-Fade-In "endOfFadeIn" float)
(define-tag timbre-Mean "timbreMean" floats)
(define-tag loudness-Dynamics-Variance "loudnessDynamicsVariance" float)
(define-tag timbre-Coeff "timbreCoeff" floats)
(define-tag pitches "pitches" floats)
(define-tag time-Loudness-Max "timeLoudnessMax" float)
(define-tag loudness-Max "loudnessMax" float)
(define-tag loudness-Begin "loudnessBegin" float)
(define-tag loudness-end "loudnessEnd" float)

(define-attribute-property duration "duration" float)
(define-attribute-property usable-duration "usableDuration" float)
(define-attribute-property start "start" float)
(define-attribute-property version "version" string)
(define-attribute-property name "name" string)

(define-element-property analysis "Analysis" object)
(define-element-property decoder "Decoder" object decoder)
(define-element-property track "Track" object  track)
(define-element-property tatums "Tatums" array tatums t)
(define-element-property section "Section" objects  sections)
(define-element-property segment "Segment" objects segments)
(define-element-property tags "Tags" plist)
(define-element-property id "id" text id t)
(define-element-property status "status" text status t)
(define-element-property input "input" text input t)
(define-element-property response "response" object)

(defun intern-analysis (response)
  response)